package com.example.side_pull_menu.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

import com.example.side_pull_menu.Fragmentkj3;
import com.example.side_pull_menu.PieChartUtil3;
import com.example.side_pull_menu.R;
import com.github.mikephil.charting.charts.PieChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.PieDataSet;
import com.github.mikephil.charting.data.PieEntry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.google.gson.Gson;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.http.GET;

import static android.support.constraint.Constraints.TAG;

public class Fragment_3 extends Fragment{
    private HashMap dataMap;
    private ListView lv;
    private List<Fragmentkj3>carlist=new ArrayList<>();
    private PieChart pieChart;
    public interface BlogService {
        @GET("aircondition")
        Call<ResponseBody> getBlog();
    }
    private Handler handler = new Handler();
    private Runnable runnable = new Runnable(){
        @Override
        public void run() {
            PieChartUtil3 pp = new PieChartUtil3();
            pp.setPieChartData1(pieChart);
            handler.postDelayed(this,360000*24);
            Log.i(TAG, "run"+"00");
        }
    };

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View view1= inflater.inflate(R.layout.fragment_3, container, false);
       initView(view1);
        handler.removeCallbacks(runnable);
        handler.postDelayed(runnable,1000);
        return view1;
    }
    private void initView(View view1){
//            dataMap=new HashMap();
//            dataMap.put("Ⅰ类水","8");
//            dataMap.put("Ⅱ类水","12");
//            dataMap.put("Ⅲ类水","31");
//            dataMap.put("Ⅳ类水","24");
//            dataMap.put("Ⅴ类水","10");
//            dataMap.put("劣Ⅴ类水","15");
        pieChart=(PieChart) view1.findViewById(R.id.pie_chart);
        PieChartUtil3.getPieChart().setPieChart(pieChart,dataMap,"温度",true);
        //点击事件
        pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
            @Override
            public void onValueSelected(Entry e, Highlight h) {
                PieEntry pieEntry=(PieEntry)e;
                pieChart.setCenterText(pieEntry.getLabel());
            }
            @Override
            public void onNothingSelected() {
            }
        });
    }
}